<?php
    $account_id = $this->session->userdata('doogy.id');
    $account_name = $this->session->userdata('account_name');
    $message_to_list = isset($message_to_list)?$message_to_list:0;
    echo $erreur;
?>
<div id="wrapper-content" style="width: 90%;">
    <div align="left" id="title_view_profile" >Inbox</div>
    <table align="center" width="100%" class="list" >
        <thead>
            <tr>
                <th colspan="3"></th>
                <th></th>
                <th></th>
            </tr>
        </thead>
        <?php if($message_details->num_rows()>0):?>
            <?php 
                $message_detail = $message_details->row();
                $avatar = './doggy_avatar/images/' . $message_detail->avatar;
                if (file_exists($avatar) AND $message_detail->avatar!=NULL) {
                    $avatar = base_url() . 'doggy_avatar/images/' . $message_detail->avatar;
                } else {
                    $avatar = root_url('doggy-flirt') . './assets/noimage.gif';
                }
                $long_date = $message_detail->posted_date;
                $now = time();
                $posted_date = timespan($long_date, $now);
            ?>
            <tr class="highlight">
            <td width="10%" valign="top" colspan="2">
                <a href="<?php echo site_url('home/compte').'/'.$message_detail->posted_by;?>"><img border="0" src="<?php echo $avatar; ?>" width="60" alt=""/></a>
            </td>
            <td colspan="2">
                <p><a style="color: #000000;text-transform: capitalize;" href="<?php echo site_url('home/compte').'/'.$message_detail->posted_by;?>"><?php echo $message_detail->display_name.' '; ?></a><?php echo $message_detail->title;?></p>
                <p><?php echo $message_detail->content; ?></p>
            </td>
            <td align="right">
                <?php echo $posted_date; ?>
            </td>
            
            <?php endif;?>
        <?php for($i=0;$i<count($reply_message);$i++): ?>
            <?php
                $aRow=$reply_message[$i];
                $title = $aRow['title'];
                $reply_sig = $i==count($reply_message)-1?'':' reply :';
                $message_id = $aRow['message_id'];
                $msg_style = '';
                if ($aRow['is_read'] == 0) {
                    $msg_style = ' style="color: blue;font-weight: bold;" ';
                } else {
                    $msg_style = ' style="color: black;" ';
                }
                $image = './doggy_avatar/images/' . $aRow['avatar'];
                if (file_exists($image)) {
                    $image = base_url() . 'doggy_avatar/images/' . $aRow['avatar'];
                } else {
                    $image = root_url('doggy-flirt') . './assets/noimage.gif';
                }

                $long_date = $aRow['commented_time'];
                $now = time();
                $posted_date = timespan($long_date, $now);?>
            <?php if(!is_message_hidden($aRow['id'])):?>
                <tr class="highlight">
                    <td width="10%" valign="top" colspan="2">
                        <a href="<?php echo site_url('home/compte').'/'.$aRow['account_id']?>"><img border="0" src="<?php echo $image; ?>" width="60" alt=""/></a>
                    </td>
                    <td>
                        <p><a style="color: #000000;text-transform: capitalize;" href="<?php echo site_url('home/compte').'/'.$aRow['account_id']?>"><?php echo $aRow['display_name'].' '; ?></a><?php echo $reply_sig.$title;?></p>
                        <p><?php echo $aRow['content']; ?></p>
                    </td>
                    <td align="right">
                        <?php echo $posted_date; ?>
                    </td>
                    <td width="70px">
                        <a class="supprimer" href="#" ><img border="0"src="<?php echo root_url('doggy-flirt') . 'assets/admin/' ?>images/supprimer.png"/></a>
                        <div style="display:none">
                            Confirmer <br/>
                            <a href="<?php echo site_url('message/delete_reply_message') . '/' . $aRow['id'].'/'.$message_to_list; ?>"> <img border="0"src="<?php echo root_url('doggy-flirt') . 'assets/admin/' ?>images/oui.png"/></a>
                            <a class="non" href="#" ><img  border="0"src="<?php echo root_url('doggy-flirt') . 'assets/admin/' ?>images/non.png"/></a>
                        </div>
                    </td>
                </tr>
                <?php endif;?>
            <?php endfor; ?>
    </table>
    <?php echo $pagination; ?>
    <?php
        $original_message_id = $message_details->num_rows()>0?$message_details->row()->id:FALSE;  
        $message_id = isset($message_id)?$message_id:$original_message_id;
        if($message_id):?>
        <?php $original_title = isset($title)?$title:$message_details->row()->title;?>
        <?php echo form_open('message/reply_message' . '/' . $message_id); ?>
        <table align="center">
            <tr>
                <td>Titre:</td>
                <td><input type="text" name="title" size="25" value="RE: <?php echo $original_title; ?>"/></td>
            </tr>
            <tr>
                <td>Contenu : </td>
                <td><textarea name="content" id="content" type="text" rows="10" cols="40"></textarea></td>
                <td><?php echo validation_errors(); ?></td>
            </tr>
            <tr>
                <td><input type="submit" name="submit" value="Répondre" /></td>
            </tr>
        </table>
        <?php echo form_close(); ?>
        <?php endif;?>                           
</div>
<!--END wrapper-content-->
